package org.example.carsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.carsystem.domain.SysRole;
import org.example.carsystem.domain.vo.RoleVo;
import org.example.carsystem.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("roles")
@CrossOrigin
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/select")
    public Map<String,Object> rolesSelect(@RequestParam(value = "roleName",required = false)String roleName,
                                          @RequestParam(value = "roleKey",required = false)String roleKey,
                                          @RequestParam(value = "status",required = false)String status,
                                          @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date createStartTime,
                                          @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date createEndTime,
                                          @RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SysRole> list = roleService.rolesSelect(roleName,roleKey,status,createStartTime,createEndTime);
        PageInfo<SysRole> info = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("list",info);
        return map;
    }

    @GetMapping("/select/all")
    public Map<String,Object> rolesSelectAll(){
        List<RoleVo> list = roleService.rolesSelectAll();
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("list",list);
        return map;
    }

    @PostMapping("/add")
    public Map<String,Object> reolesAdd(@RequestBody SysRole sysRole){
        Map<String, Object> map = new HashMap<>();
        
        return map;
    }
}
